package com.tn.service.securewhitelist.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tn.dao.mbpdao.SecureWhitelist;
import com.tn.dao.mbpdao.SecureWhitelistMapper;
import com.tn.service.securewhitelist.SecureWhitelistService;
import com.tn.utils.DateUtil;
import com.tn.utils.JsonUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YuzSuzuki
 * @since 2023-06-01
 */
@Log4j2
@Service
public class SecureWhitelistServiceImpl extends ServiceImpl<SecureWhitelistMapper, SecureWhitelist> implements SecureWhitelistService {


    @Override
    public void cancelWhiteListMember(List<String> license) {
        log.info("安全系统取消白名单："+ JsonUtil.obj2String(license));
        UpdateWrapper<SecureWhitelist>wrapper=new UpdateWrapper<>();
        wrapper.in("license",license);
        wrapper.set("state",0);
        baseMapper.update(null,wrapper);
    }

    @Override
    public void updateWhiteListMember(SecureWhitelist secureWhitelist) {
        log.info("安全系统更新白名单："+ JsonUtil.obj2String(secureWhitelist));
        UpdateWrapper<SecureWhitelist>wrapper=new UpdateWrapper<>();
        wrapper.eq("license",secureWhitelist.getLicense());
        wrapper.set("start_time",secureWhitelist.getStartTime());
        wrapper.set("end_time",secureWhitelist.getEndTime());
        wrapper.set("update_time", DateUtil.dateToString(new Date()));
        baseMapper.update(null,wrapper);
    }
}
